package com.hongye.house.controller;

import com.hongye.common.utils.PageUtils;
import com.hongye.common.utils.R;
import com.hongye.house.entity.LeaseHomeEntity;
import com.hongye.house.entity.SaleHomeEntity;
import com.hongye.house.fegin.ProprietaryFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hongye.house.entity.LeaseHomeEntity;
import com.hongye.house.service.LeaseHomeService;
import com.hongye.common.utils.PageUtils;
import com.hongye.common.utils.R;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 房源：租房表
 *
 * @author lins
 * @email 695565697@qq.com
 * @date 2021-10-14 13:32:23
 */
@RestController
@RequestMapping("house/leasehome")
public class LeaseHomeController {
    @Autowired
    private LeaseHomeService leaseHomeService;
    @Autowired
    private ProprietaryFeign proprietaryFeign;



        /*
    es搜索
     */
    @RequestMapping("/esleasesearch")
    public List<LeaseHomeEntity> esleasesearch(@RequestParam("housePrice") Integer housePrice) throws Exception {
        List<LeaseHomeEntity> leaseHomeEntities=leaseHomeService.esleasesearch(housePrice);
        return leaseHomeEntities;
    }


    /*
首先把房子的信息传入es
 */
    //@Scheduled(fixedRate = 2000)
    public void esinsert(){
        leaseHomeService.esinsert();
    }



    /*
    经纪人小程序端-首页数据提供接口
    出租房数首页数据提供接口
    */
    @RequestMapping("/numberofrentals")
    public R numberofrentals(){
        Integer  numberofrentals= leaseHomeService.numberofrentals();
        return R.ok().put("data",numberofrentals);
    }


        /*
    租房列表
     */
    @RequestMapping("/rentinglist/{houseagent}")
    public List<LeaseHomeEntity> rentinglist(@PathVariable("houseagent")Integer houseagent){
        List<LeaseHomeEntity> leaseHomeEntities= leaseHomeService.rentinglist(houseagent);
        return leaseHomeEntities;
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = leaseHomeService.queryPage(params);

        return R.ok().put("page", page);
    }






    /**
     * 信息
     */
    @RequestMapping("/info/{houseId}")
    public R info(@PathVariable("houseId") Integer houseId){
		LeaseHomeEntity leaseHome = leaseHomeService.getById(houseId);

        return R.ok().put("leaseHome", leaseHome);
    }

    /**
public void list(){}

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody LeaseHomeEntity leaseHome){
		leaseHomeService.updateById(leaseHome);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] houseIds){
		leaseHomeService.removeByIds(Arrays.asList(houseIds));

        return R.ok();
    }

}
